package com.simen.hellobytes.android;

import android.content.Context;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
import android.os.Debug;
import android.provider.Settings;

/**
 * author: SimenHi
 * create time: 2020-09-23 17:47
 * description:
 */
public class CheckDebugUtil {

    public static boolean isAdbEnabled(Context context){
        return "1".equals(Settings.Global.getString(context.getApplicationContext().getContentResolver(), Settings.Global.ADB_ENABLED));
    }

    public static boolean isDevelopmentSettingsEnabled(Context context){
        return "1".equals(Settings.Global.getString(context.getApplicationContext().getContentResolver(), Settings.Global.DEVELOPMENT_SETTINGS_ENABLED));
    }

    public static String getSettingDebugApp(Context context){
        return Settings.Global.getString(context.getApplicationContext().getContentResolver(), Settings.Global.DEBUG_APP);
    }

    /**
     * @return 当前应用是否可以调试
     */
    public static boolean isDebuggable(Context context) {
        boolean debuggable = false;
        PackageManager pm = context.getPackageManager();
        try {
            ApplicationInfo appInfo = pm.getApplicationInfo(context.getPackageName(), 0);
            debuggable = (0 != (appInfo.flags & ApplicationInfo.FLAG_DEBUGGABLE));
        } catch (PackageManager.NameNotFoundException e) {
        }
        return debuggable;
    }

    /**
     * @return 当前app是否正在被调试
     */
    public static boolean isDebugging(){
        return Debug.isDebuggerConnected();
    }

}
